<template>
  <div
    class="modal fade"
    tabindex="-1"
    role="dialog"
    aria-hidden="true"
    :id="id"
  >
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">
            <slot name="title"> 新建客户服务费模板 </slot>
          </h4>
          <button
            type="button"
            class="btn-close"
            data-bs-dismiss="modal"
            aria-label="Close"
          ></button>
        </div>
        <div class="modal-body">
          <form role="form" class="form-horizontal">
            <div class="row mb-2">
              <label class="form-label col-4 text-end"> 模板代码 </label>
              <div class="col-8">
                <input type="text" class="form-control" v-model.trim="code" />
                <span class="text-muted small"
                  >建议用字母或数字标识，长度不超过5</span
                >
              </div>
            </div>
            <div class="row mb-2">
              <label class="form-label col-4 text-end"> 模板名称 </label>
              <div class="col-8">
                <input type="text" class="form-control" v-model.trim="name" />
                <span class="text-muted small">最大50个字符</span>
              </div>
            </div>
            <div class="row mb-2">
              <label class="form-label col-4 text-end"> 价格模式 </label>
              <div class="col-8">
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="0"
                    v-model.number="flightPriceMode"
                  />
                  <label class="form-check-label">黑屏公布运价</label>
                </div>
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="1"
                    v-model.number="flightPriceMode"
                  />
                  <label class="form-check-label">大客户优选票面</label>
                </div>
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="2"
                    v-model.number="flightPriceMode"
                  />
                  <label class="form-check-label">底价(代理费全返)</label>
                </div>
              </div>
            </div>
            <div class="row mb-2">
              <label class="form-label col-4 text-end">
                机票出票服务费
              </label>
              <div class="col-8">
                <input
                  type="text"
                  class="form-control"
                  v-model.number="flightTicketingFee"
                />
                <span class="text-muted small">按每人每段收取</span>
              </div>
            </div>
            <div class="row mb-2">
              <label class="form-label col-4 text-end"> 保险金额 </label>
              <div class="col-8">
                <input
                  type="text"
                  class="form-control"
                  v-model.number="flightInsurance"
                />
                <span class="text-muted small"
                  >按每人每段购买，此项与机票出票服务费二选一</span
                >
              </div>
            </div>
            <div class="row mb-2">
              <label class="form-label col-4 text-end">
                机票退票服务费
              </label>
              <div class="col-8">
                <input
                  type="text"
                  class="form-control"
                  v-model.number="flightRefundFee"
                />
                <span class="text-muted small">按每人每段收取</span>
              </div>
            </div>
            <div class="row mb-2">
              <label class="form-label col-4 text-end">
                机票改签服务费
              </label>
              <div class="col-8">
                <input
                  type="text"
                  class="form-control"
                  v-model.number="flightChangeFee"
                />
                <span class="text-muted small">按每人每段收取</span>
              </div>
            </div>
            <div class="row mb-2">
              <label class="form-label col-4 text-end">
                服务费报表显示
              </label>
              <div class="col-8">
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="0"
                    v-model.number="reportShowFee"
                  />
                  <label class="form-check-label">合并到航司价</label>
                </div>
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="1"
                    v-model.number="reportShowFee"
                  />
                  <label class="form-check-label">单列显示</label>
                </div>
              </div>
            </div>
            <div class="row mb-2">
              <label class="form-label col-4 text-end"> GP票模式 </label>
              <div class="col-8">
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="0"
                    v-model.number="gpMode"
                  />
                  <label class="form-check-label">不可开GP</label>
                </div>
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="1"
                    v-model.number="gpMode"
                  />
                  <label class="form-check-label">可开GP</label>
                </div>
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="2"
                    v-model.number="gpMode"
                  />
                  <label class="form-check-label">仅开GP</label>
                </div>
              </div>
            </div>
            <div class="row mb-2">
              <label class="form-label col-4 text-end"> 强度 </label>
              <div class="col-8">
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="0"
                    v-model.number="strength"
                  />
                  <label class="form-check-label">弱规则</label>
                </div>
                <div class="form-check form-check-inline">
                  <input
                    class="form-check-input"
                    type="radio"
                    value="10"
                    v-model.number="strength"
                  />
                  <label class="form-check-label">强规则</label>
                </div>
              </div>
              <span class="offset-4 text-muted small"
                >强规则：订单中录入的服务费与规则不符时，不允许完成订单。</span
              >
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button
            type="button"
            class="btn btn-secondary me-2"
            data-bs-dismiss="modal"
          >
            关闭
          </button>
          <button type="button" class="btn btn-primary" @click.stop="ok()">
            确定
          </button>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
import $ from "jquery";

export default {
  props: {
    nullable: {
      type: Boolean,
      default: true,
    },
    id: {
      type: String,
      default: "customerServiceTemplateModal",
    },
    departments: {
      type: Array,
    },
  },
  data() {
    return {
      resolve: "",
      reject: "",
      promise: "",

      tplId: 0,
      code: "",
      name: "",
      flightPriceMode: 0,
      flightTicketingFee: 0,
      flightInsurance: 0,
      flightRefundFee: 0,
      flightChangeFee: 0,
      reportShowFee: 0,
      gpMode: 0,
      strength: 0,

      myModal: null,
    };
  },
  methods: {
    ok: function () {
      this.hideModal();

      this.resolve({
        id: this.tplId,
        name: this.name,
        code: this.code,
        flightPriceMode: this.flightPriceMode,
        flightTicketingFee: this.flightTicketingFee,
        flightInsurance: this.flightInsurance,
        flightRefundFee: this.flightRefundFee,
        flightChangeFee: this.flightChangeFee,
        reportShowFee: this.reportShowFee,
        gpMode: this.gpMode,
        strength: this.strength
      });
    },
    modal: function (v) {
      this.tplId = v.id;
      this.code = v.code;
      this.name = v.name;

      this.flightPriceMode = v.flightPriceMode;
      this.flightTicketingFee = v.flightTicketingFee;
      this.flightInsurance = v.flightInsurance;

      this.flightRefundFee = v.flightRefundFee;
      this.flightChangeFee = v.flightChangeFee;
      this.reportShowFee = v.reportShowFee;
      this.gpMode = v.gpMode;
      this.strength = v.strength;

      this.showModal();

      this.promise = new Promise((resolve, reject) => {
        this.resolve = resolve;
        this.reject = reject;
      });
      return this.promise;
    },
    showModal: function () {
      this.getMyModal().show();
    },
    hideModal: function () {
      this.getMyModal().hide();
    },
    getMyModal: function () {
      if (this.myModal === null) {
        let myModalEl = $(this.$el).get(0);
        this.myModal = new bootstrap.Modal(myModalEl, {
          keyboard: true,
        });
      }

      return this.myModal;
    },
  },
};
</script>
